@extends('develop.layoutList')

@section('title')
    <li class="cur">
        <span>日志清除列表</span>
    </li>
@endsection

@section('css')
    <style>
        .form-group{margin-bottom:9px; padding:0px;}
    </style>

@endsection

@section('btn')
    <button class="btn btn-primary" type="button" onclick="Log.edit();">添加</button>
@endsection
@section('search')

<input type="text"  class="form-control" name="tableName" id="tableName" value="" style="width:150px;" placeholder="请输入表名">
<input type="text"  class="form-control" name="tableRemark" id="tableRemark" value="" style="width:150px;" placeholder="请输入表备注">
<input type="text"  class="form-control" name="days" id="days" value="" style="width:150px;" placeholder="请输入清除天数">

@endsection

@section('js')
    <script>

        var bootstrap_table_ajax_url = '/lar/develop/log/search';
        bootstrap_table({
        sortName: 'manageId', //排序字段
        sortOrder: 'DESC',//排序方式
        columns: [ //字段
            { title: '操作', field: 'operate', align: 'center' },
            { title: '表名', field: 'tableName', align: 'left'},
            { title: '表备注', field: 'tableRemark', align: 'left' },
            { title: '清除天数',  field: 'days', align: 'left' }
        ]
    });

    var Log = {

        //保存、编辑
        edit: function ( manageId ) {

            var html='<form id="pop_form" onsubmit="return false;" class="form-horizontal" role="form" style="margin-top: 10px">';
                html+='<input type="hidden" id="manageId" name="manageId" value="">';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="tableName"><span class="red">*</span>表名：</label>';
            html+='<div class="col-sm-8">';
            html+='<input class="form-control w300" style="width: 300px;" type="text" id="tableName" name="tableName" placeholder="请输入表名"  value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="tableRemark"> <span class="red">*</span>表备注：</label>';
            html+='<div class="col-sm-8">';
            html+='<input class="form-control w300" style="width: 300px;" type="text" id="tableRemark" name="tableRemark"  placeholder="请输入表备注" value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" for="days"><span class="red">*</span>清除天数：</label>';
            html+='<div class="col-sm-8">';
            html+='<input class="form-control w300" style="width: 300px;" type="text" id="days" name="days"  placeholder="请输入清除天数" value=""  autocomplete="off" />';
            html+='</div>';
            html+='</div>';
            html+='</form>';

            this.reset_pop();
            var title ="";

            if ( manageId ) {
                title = "修改日志表";
            } else {
                title ="添加日志表";
            }

            layer.open({
                type:1,
                title: title,       //弹出层标题
                area:'600px',
                content:html,
                btn: ['确定', '取消'],
                yes: function(){
                    Log.store( manageId );
                },
                btn2: function(){
                    Log.close();
                }
            });

            if ( manageId ) {
                var load_index = layer.load();

                E.ajax({
                    type:'get',
                    url:'/lar/develop/log/get/'+manageId,
                    success:function (obj) {
                        layer.close(load_index);
                        if (obj.code == 200) {
                            $('#pop_form').find('#manageId').val(obj.data.manageId);
                            $('#pop_form').find('#tableName').val(obj.data.tableName);
                            $('#pop_form').find('#tableRemark').val(obj.data.tableRemark);
                            $('#pop_form').find('#days').val(obj.data.days);
                        } else {
                            layer.alert(obj.message,{icon:2});
                        }
                    }
                });
            }
        },

        //保存校验
        store:function( manageId ) {

            var formData = E.getFormValues('pop_form');

            var msg = '';

            if ( E.isEmpty(formData.tableName) ) {
                msg += '请输入表名<br/>';
            }
            if ( E.isEmpty(formData.tableRemark) ) {
                msg += '请输入表备注<br/>';
            }
            if ( !E.isInt(formData.days) ) {
                msg += '请输入正确的清除天数<br/>';
            }
            if ( !E.isEmpty( msg ) ) { //存在错误，返回不进行提交
                layer.alert(msg,{icon:2});
                return false;
            }

            layer.confirm("您确认保存该日志表吗？",{icon:3,offset:'50px'}, function ( index ) {
                layer.close( index );
                E.ajax({
                    type:'get',
                    url:'/lar/develop/log/store',
                    data:formData,
                    dataType:'json',
                    success:function ( obj ) {

                        if ( obj.code == 200 ) {
                            layer.alert('日志表保存成功', {icon: 1, offset: '70px', time: 2000});
                            Log.reset_pop();
                            Log.load();
                        } else {
                            layer.alert(obj.message,{icon:2});
                        }
                    }
                });
            });
        },

        //重置弹出层
        reset_pop: function () {
            $('#pop_form').find('#manageId').val("");
            $('#pop_form').find('#tableName').val("");
            $('#pop_form').find('#tableRemark').val("");
            $('#pop_form').find('#days').val("");
        },

        //删除日志
        del:function( manageId ) {

            layer.confirm('确认删除这个日志表吗?',{icon:3}, function (index) {
                layer.close( index );
                E.ajax({
                    type:'get',
                    url:'/lar/develop/log/delete/'+manageId,
                    success:function( obj ) {
                        if( obj.code == 200 ) {
                            layer.alert('日志表删除成功', {icon: 1, offset: '70px', time: 2000});
                            Log.close();
                            Log.load();
                        }else{
                            layer.alert(obj.message,{icon:2});
                            Log.load();
                        }
                    }
                });
            });
        },

        //重新加载表格
        load: function() {
            //刷新表格
            $('#table').bootstrapTable('refresh');
        },

        close:function(){
            layer.closeAll();
        },

        //重置按钮执行函数
        reset: function(){
            $('#tableName').val('');
            $('#tableRemark').val('');
            $('#days').val('');
            Log.load();
        }
    }

</script>
@endsection